function Normal2Rotation(%normal)  
{  
	if(getWord(%normal, 2) == 1 || getWord(%normal, 2) == -1)
	{	
		%rotAxis = vectorNormalize(vectorCross(%normal, "0 1 0"));
	}
	else
	{
		%rotAxis = vectorNormalize(vectorCross(%normal, "0 0 1"));
	}

	%initialAngle = mACos(vectorDot(%normal, "0 0 1"));
	%rotation = %rotAxis SPC mRadtoDeg(%initialAngle);
	
	return %rotation;  
}
function vectorClosestPointAngle(%vector, %startPoint, %point)
{
	%vN = vectorNormalize(%vector);
	%v2 = vectorSub(%point, %startPoint);
	%dot = vectorDot(%vN, vectorNormalize(%v2));
	
	%closestPoint = vectorAdd(%startPoint, vectorScale(%vN, %dot * vectorLen(%v2)));
	%angle = mACos(%dot);
	
	return %closestPoint SPC %angle;
}
function calcAdditiveRGB(%color1, %color2)
{
	%r1 = getWord(%color1, 0);
	%g1 = getWord(%color1, 1);
	%b1 = getWord(%color1, 2);
	%a1 = getWord(%color1, 3);
			
	%r2 = getWord(%color2, 0);
	%g2 = getWord(%color2, 1);
	%b2 = getWord(%color2, 2);
	%a2 = getWord(%color1, 3);

	return (%r1 + %r2) / 2 SPC (%g1 + %g2) / 2 SPC (%b1 + %b2) / 2 SPC (%a1 + %a2) / 2;
}

function calcAdditiveRGB_emphasis(%color1, %color2, %e)
{
	%r1 = getWord(%color1, 0);
	%g1 = getWord(%color1, 1);
	%b1 = getWord(%color1, 2);
	%a1 = getWord(%color1, 3);
			
	%r2 = getWord(%color2, 0);
	%g2 = getWord(%color2, 1);
	%b2 = getWord(%color2, 2);
	%a2 = getWord(%color1, 3);

	for(%i = 0; %i < %e; %i++)
	{
		%r = %r + %r1;
		%g = %g + %g1;
		%b = %b + %b1;
		%a = %a + %a1;
	}
	%r = %r + %r2;
	%g = %g + %g2;
	%b = %b + %b2;
	%a = %a + %a2;
	
	return %r / (%e + 1) SPC %g / (%e + 1) SPC %b / (%e + 1) SPC %a / (%e + 1);
}